﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web.group
{
    public partial class phonebookedit : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Request["phonebookid"]))
            {
                throw new Base.CustomException("缺少参数phonebookid");
            }

            Hashtable phonebook = PhoneBook.Group.PhoneBook.get(Request["phonebookid"]);
            if (phonebook == null)
            {
                throw new Base.CustomException("参数phonebookid不正确");
            }

            Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["userid"]));
            if (!user["groupid"].Equals(phonebook["groupid"]))
            {
                throw new Base.CustomException("无权限修改此部门");
            }

            if (!IsPostBack)
            {
                txb_phonebookname.Text = Commons.StrUtil.FormatValue(phonebook["phonebookname"]);
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            Hashtable phonebook = PhoneBook.Group.PhoneBook.get(Request["phonebookid"]);
            if (phonebook["phonebookname"] != txb_phonebookname.Text)
            {
                AddLog("修改了通讯录信息。名称：{0}->{1}", phonebook["phonebookname"], txb_phonebookname.Text);
            }
            
            phonebook["phonebookname"] = txb_phonebookname.Text;

            PhoneBook.Group.PhoneBook.edit(phonebook);
            Helper.ShowMessage(u_message, controls.UCMessageType.success, "保存成功");
        }   
    }
}